%%%-----------------------------------
%%% @Module  : pt_20
%%% @Author  : xws
%%% @Created : 2016.9.14
%%% @Description: 
%%%-----------------------------------
-module(pt_20).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_20_award.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% 20000 获取玩家奖励信息
read(20000, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_player_award_data, Bin), 
    #c2s_get_player_award_data{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 20001 领取系统补偿
read(20001, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_system_award, Bin),    
    #c2s_get_system_award{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 20002 领取玩家每日奖励
read(20002, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_day_award, Bin),    
    #c2s_get_day_award{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 20003 领取玩家VIP奖励
read(20003, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_vip_award, Bin),    
    #c2s_get_vip_award{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 20004 领取明日礼包奖励
read(20004, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_tomorrow_award, Bin),    
    #c2s_get_tomorrow_award{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% 20000 获取玩家奖励信息
write(20000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_player_award_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20000, ServerData)};

%% 20001 领取系统补偿
write(20001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_system_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20001, ServerData)};

%% 20002 领取玩家每日奖励
write(20002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_day_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20002, ServerData)};

%% 20003 领取玩家VIP奖励
write(20003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_vip_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20003, ServerData)};

%% 20004 领取明日礼包奖励
write(20004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_tomorrow_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20004, ServerData)};

%% 20005 领取明日礼包奖励
write(20005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_tomorrow_status, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20005, ServerData)};

%% 20009 领取明日礼包奖励
write(20009, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_get_box, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(20009, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_20 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
